using System.Collections.Generic;
using UnityEngine;

public class RagdollCtrl : MonoBehaviour
{
    private bool m_ShowRagdoll;
    public bool showingRagdoll => m_ShowRagdoll;

    public Animator animator;
    List<Rigidbody> m_Rigids = new List<Rigidbody>();
    public Vector3 position => transform.position;

    public Transform rigidsParent;

    private void Awake()
    {
        if (animator == null)
            animator = GetComponentInChildren<Animator>();

        if (rigidsParent)
        {
            foreach (var rigid in rigidsParent.GetComponentsInChildren<Rigidbody>())
            {
                m_Rigids.Add(rigid);
            }
        }
    }

    private void Start()
    {
        
    }

    public /*virtual*/ void ShowNormal()
    {
        m_ShowRagdoll = false;

        animator.enabled = true;
        foreach(var rigid in m_Rigids)
        {
            rigid.isKinematic = true;
            rigid.GetComponent<Collider>().isTrigger = true;
        }
    }

    //public bool delayDisativeCol;

    public /*virtual*/ void ShowRagdoll()
    {
        m_ShowRagdoll = true; 
        
        animator.enabled = false;
        foreach (var rigid in m_Rigids)
        {
            rigid.isKinematic = false;
            rigid.GetComponent<Collider>().isTrigger = false;
        }
        //if (delayDisativeCol)
        //{
        //    DoActionDelay.DelayAction(1, () =>
        //    {
        //        foreach (var rigid in m_Rigids)
        //        {
        //            rigid.isKinematic = true;
        //        }
        //    });
        //}
    }
}